package model;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * 用户实体类
 */
public class User {
    private int userId;
    private String studentId;
    private String name;
    private String password;
    private String phone;
    private String email;
    private int userType; // 0: 学生, 1: 管理员
    private int creditScore; // 信誉分，初始值100
    private boolean isBanned; // 是否被禁用预约
    private LocalDate banUntilDate; // 禁用截止日期
    private LocalDateTime createTime;

    public User() {
    }

    public User(String studentId, String name, String password, String phone, String email, int userType) {
        this.studentId = studentId;
        this.name = name;
        this.password = password;
        this.phone = phone;
        this.email = email;
        this.userType = userType;
        this.creditScore = 100; // 初始信誉分100分
        this.isBanned = false;
        this.banUntilDate = null;
        this.createTime = LocalDateTime.now();
    }

    // Getters and Setters
    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getUserType() {
        return userType;
    }

    public void setUserType(int userType) {
        this.userType = userType;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public boolean isAdmin() {
        return userType == 1;
    }

    public int getCreditScore() {
        return creditScore;
    }

    public void setCreditScore(int creditScore) {
        this.creditScore = creditScore;
    }

    public boolean isBanned() {
        return isBanned;
    }

    public void setBanned(boolean banned) {
        isBanned = banned;
    }

    public LocalDate getBanUntilDate() {
        return banUntilDate;
    }

    public void setBanUntilDate(LocalDate banUntilDate) {
        this.banUntilDate = banUntilDate;
    }

    // 工具方法
    public boolean canMakeReservation() {
        return !isBanned || (banUntilDate != null && banUntilDate.isBefore(LocalDate.now()));
    }

    public String getCreditScoreLevel() {
        if (creditScore > 100)
            return "优秀";
        else if (creditScore >= 80)
            return "良好";
        else if (creditScore >= 60)
            return "一般";
        else if (creditScore >= 40)
            return "较差";
        else
            return "极差";
    }

    public boolean isLowCreditScore() {
        return creditScore < 50;
    }
}
